// Copyright (C) 2005 Taylor L. Riché <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// 	$Id: ApplicationGraph.hh 82 2005-08-02 17:17:38Z richetl $	
//

#ifndef APPLICATIONGRAPH_H
#define APPLICATIONGRAPH_H

#include <assert.h>
#include <list>
#include <map>
#include <string>

#ifdef LEE_BUILD
#include "NetInterface.hh"
#include "PPFunction.hh"
#include "Synchronized.hh"
#include "Scheduler.hh"
#else
#include <lee/NetInterface.hh>
#include <lee/PPFunction.hh>
#include <lee/Synchronized.hh>
#include <lee/Scheduler.hh>
#endif

namespace lee {

  class Scheduler;

  class ApplicationGraph : public Synchronized
  {
    friend class Scheduler;
    std::map<std::string, PPFunction*> ppfMap;
    std::map<std::string, std::map<int, PPFunction*> *> appGraph;
    int uid;
  protected:
    virtual void init() {}
  public:
    ApplicationGraph(int i) : uid(i) {}
    virtual ~ApplicationGraph() {}
    PPFunction * getNextPPFunction(std::string ppfName, int exitPoint);
    void makeConnection(std::string leftPpf, int leftPort, std::string rightPpf);
    template<typename T> void createPPF(std::string ppfName) {
      Synchronized::Scope mutex(this);
      T * ppf = new T(ppfName);
      ppfMap[ppfName] = ppf;
      notifyAll();
      return;
    }
    void createNetInterfaceEntry() {
      appGraph["eth0"] = new std::map<int, PPFunction*>();
    }

    void addPpfAfter(std::string origPpf, int origPort, 
		     std::string newPpf, int newPort);
    void addPpfBefore(std::string newPpf, int newPort, std::string origPpf);
    void deletePPFunction(std::string ppfName);
  };
}

#endif // APPLICATIONGRAPH_H
